import React, { PureComponent } from 'react';
import { BrowserRouter, Switch, Route, Redirect } from 'react-router-dom';
import {
  LOGIN_PATH, REGISTER_PATH, PAN_ERROR, PAN_PATH,
} from './constant';
import Error from './pages/500';
import Login from './pages/Login/index';
import Pan from './pages/Pan/index';
import Register from './pages/Register/index';

class App extends PureComponent {

  // 禁止浏览器右键事件
  forbiddenRightMouseClick = () => {
    if (window.Event) {document.captureEvents(Event.MOUSEUP);}

    function nocontextmenu () {
      event.cancelBubble = true
      event.returnValue = false;

      return false;
    }
    function norightclick (e) {
      if (window.Event) {
        if (e.which == 2 || e.which == 3) {return false;}
      } else if (event.button == 2 || event.button == 3) {
        event.cancelBubble = true
        event.returnValue = false;
        return false;
      }

    }
    document.oncontextmenu = nocontextmenu;  // for IE5+
    document.onmousedown = norightclick;  // for all others
  }

  componentDidMount () {
    this.forbiddenRightMouseClick()
  }

  render () {
    return (
      <>
        <BrowserRouter>
          <Switch>
            <Route path={PAN_PATH} component={Pan} />
            <Route path={REGISTER_PATH} component={Register} />
            <Route path={PAN_ERROR} component={Error} />
            <Route path={LOGIN_PATH} component={Login} />
            <Redirect to={LOGIN_PATH}/>
          </Switch>
        </BrowserRouter>
      </>
    );
  }
}

export default App;
